package com.sheep.classroompie.controller;


import com.sheep.classroompie.entity.Comment;
import com.sheep.classroompie.entity.Course;
import com.sheep.classroompie.entity.Homework;
import com.sheep.classroompie.entity.SubmitHomework;
import com.sheep.classroompie.service.HomeworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin("http://localhost:8080")
@RequestMapping("/homework")
public class HomeworkController {
  @Autowired
  HomeworkService homeworkService;
  @RequestMapping("/selectHomeworksByCourseId")
  @ResponseBody
  public List<Homework> selectHomeworksByCourseId(@RequestBody Course course){
    String courseId = course.getCourseId();
    return homeworkService.selectHomeworksByCourseId(courseId);
  }
  @RequestMapping("/selectHomeworkById")
  @ResponseBody
  public Homework selectHomeworksById(@RequestBody Homework homework){
    Integer id = homework.getId();
    return homeworkService.selectHomeworksById(id);
  }
  @RequestMapping("/addHomework")
  @ResponseBody
  public Boolean addHomework(@RequestBody Homework homework){
    System.out.println("附件:" + homework.getAttachment());
    return homeworkService.addHomework(homework);
  }
  @RequestMapping("/addSubmitHomework")
  @ResponseBody
  public void addSubmitHomework(@RequestBody SubmitHomework submitHomework){
    submitHomework.setStatus("未提交");
    homeworkService.addSubmitHomework(submitHomework);
  }
  @RequestMapping("/selectSubmitHomeworkById")
  @ResponseBody
  public SubmitHomework selectSubmitHomeworkById(@RequestBody SubmitHomework submitHomework){
    if(homeworkService.selectSubmitHomeworkById(submitHomework) == null){
      System.out.println("往往");
    }
    return homeworkService.selectSubmitHomeworkById(submitHomework);
  }
  @RequestMapping("/deleteHomework")
  @ResponseBody
  public Boolean deleteHomework(@RequestBody Homework homework){
    Integer homeworkId = homework.getId();
    return homeworkService.deleteHomework(homeworkId);
  }
  @RequestMapping("/uploadFile")
  @ResponseBody
  public Boolean uploadFile(@RequestBody SubmitHomework submitHomework){
    System.out.println(submitHomework.getSubmitAttachment());
    return homeworkService.uploadFile(submitHomework);
  }
  @RequestMapping("/submit")
  @ResponseBody
  public void submit(@RequestBody SubmitHomework submitHomework){
    homeworkService.submit(submitHomework);
  }
  @RequestMapping("/selectSubmitHomeworkByStatus")
  @ResponseBody
  public List<SubmitHomework> selectSubmitHomeworkByStatus(@RequestBody SubmitHomework submitHomework){
    return homeworkService.selectSubmitHomeworkByStatus(submitHomework);
  }
  @RequestMapping("/scoring")
  @ResponseBody
  public void scoring(@RequestBody SubmitHomework submitHomework){
    homeworkService.scoring(submitHomework);
  }
  @RequestMapping("/updateHomework")
  @ResponseBody
  public void updateHomework(@RequestBody Homework homework){
    homeworkService.updateHomework(homework);
  }
  @RequestMapping("/addComment")
  @ResponseBody
  public void addComment(@RequestBody Comment comment){
    System.out.println(comment.getUserId());
    homeworkService.addComment(comment);
  }
  @RequestMapping("/queryComments")
  @ResponseBody
  public List<Comment> queryComments(@RequestBody Comment comment){
    return homeworkService.queryComments(comment);
  }
}
